<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>计算器练习</title>
</head>
<body>
<div>
    <input type="text" v-model="num1">
    <input type="text" v-model="num2">
    <input type="button" value="加" @click="f('+')">
    <input type="button" value="减" @click="f('-')">
    <input type="button" value="乘" @click="f('*')">
    <input type="button" value="除" @click="f('/')"><br>
    <h1>结果:{{result}}</h1>
</div>
<script src="../js/vue.js"></script>
<script>
    let v = new Vue({
        el:"div",
        data:{
            result:"",
            num1:"",
            num2:"",
        },
        methods:{
            f(x){
                //eval() 方法可以将字符串以代码的形式执行
                v.result = eval(v.num1*1+x+v.num2*1);
            }
        }
    })
</script>
</body>
</html>